package com.gz.lservlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(urlPatterns = "/hiServlet")
public class HiServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext servletContext = request.getServletContext();
        servletContext.setAttribute("name", "名字");
        servletContext.setAttribute("name", "新名字");
        servletContext.removeAttribute("name");

        HttpSession session = request.getSession();
        session.setAttribute("age",20);
        session.setAttribute("age",23);
        session.setAttribute("wage",100000);
        session.removeAttribute("age");




        System.out.println("HiServlet 处理完毕");
    }
}
